home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / COMMON / mouse.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  2KB  |  122 lines

  1. /* --------------------------------- mouse.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Handler for the mouse as a pointing device for UNIX/X11 & mswin.
  8. */
  9.  
  10. #include "fly.h"
  11. #include "mouse.h"
  12.  
  13.  
  14. #define USELOG        0x0001        /* log scale on x/y (default) */
  15.  
  16. #define PO        p->opt
  17. #define FA1D        PO[0]
  18. #define FA1F        PO[1]
  19. #define FA2D        PO[2]
  20. #define FA2F        PO[3]
  21. #define FSPEEDX        PO[4]
  22. #define FSPEEDY        PO[5]
  23. #define FOPTS        PO[6]
  24.  
  25. static int FAR
  26. Mcal (POINTER *p)
  27. {return (0);}
  28.  
  29. static int FAR
  30. Minit (POINTER *p, char *options)
  31. {
  32.     long    l;
  33.  
  34.     if (get_narg (options, "sx=", &l) || l <= 0)
  35.         FSPEEDX = 10;
  36.     else
  37.         FSPEEDX = (int)l;
  38.  
  39.     if (get_narg (options, "sy=", &l) || l <= 0)
  40.         FSPEEDY = 10;
  41.     else
  42.         FSPEEDY = (int)l;
  43.  
  44.     if (get_arg (options, "linear"))
  45.         FOPTS &= ~USELOG;
  46.     else
  47.         FOPTS |= USELOG;
  48.  
  49.     return (0);
  50. }
  51.  
  52. static void FAR
  53. Mterm (POINTER *p)
  54. {}
  55.  
  56. static int FAR
  57. Mread (POINTER *p, int transfer)
  58. {
  59.     int    reading, win_x, win_y, sizex, sizey, nbtn;
  60.     char    btn[36];
  61.  
  62.     if (!Gr)
  63.         return (-1);
  64.  
  65.     if (T(reading = GetMouse (&win_x, &win_y, btn, &nbtn)))
  66.         return (reading);
  67.  
  68.     sizex = fmul (CW->orgx, CS->sizex);
  69.     sizey = fmul (CW->orgy, CS->sizey);
  70.     win_x -= sizex + CS->minx;
  71.     win_y -= sizey + CS->miny;
  72.  
  73.     sizex = fmul (CW->maxx, CS->sizex);
  74.     sizey = fmul (CW->maxy, CS->sizey);
  75.  
  76.     reading = muldiv (win_y, 100, sizey);        /* y */
  77.     reading = muldiv (reading*FA2D, 10, FSPEEDY);
  78.     if (reading > 100)
  79.         reading = 100;
  80.     if (reading < -100)
  81.         reading = -100;
  82.     p->a[FA2F] = reading;
  83.     if (transfer)
  84.         p->l[FA2F] = (FOPTS & USELOG) ? lin2log (reading) : reading;
  85.  
  86.     reading = muldiv (win_x, 100, sizex);        /* x */
  87.     reading = muldiv (reading*-FA1D, 10, FSPEEDX);
  88.     if (reading > 100)
  89.         reading = 100;
  90.     if (reading < -100)
  91.         reading = -100;
  92.     p->a[FA1F] = reading;
  93.     if (transfer)
  94.         p->l[FA1F] = (FOPTS & USELOG) ? lin2log (reading) : reading;
  95.  
  96.     do_btns (p, btn, nbtn);
  97.  
  98.     return (0);
  99. }
  100.  
  101. struct PtrDriver NEAR PtrMouse = {
  102.     "MOUSE",
  103.     0,
  104.     NULL,    /* extra */
  105.     Minit,
  106.     Mterm,
  107.     Mcal,
  108.     Mcal,            /* center */
  109.     Mread,
  110.     std_key
  111. };
  112.  
  113. #undef USELOG
  114. #undef PO
  115. #undef FA1D
  116. #undef FA1F
  117. #undef FA2D
  118. #undef FA2F
  119. #undef FSPEEDX
  120. #undef FSPEEDY
  121. #undef FOPTS
  122.